clear all
close all

%Figure: Common facots of each hzd rate
data=xlsread('4Figures\Figure_3_data.xlsx');

nber=data(:,1);
%z-score everything
data(:,2:end)=data(:,2:end)./kron(std(data(:,2:end)),ones(length(data(:,2:end)),1));

% data=hpfilter(data,100);

jue=data(:,2:4);
jeu=data(:,5:7);
jei=data(:,8:10);
jui=data(:,11:13);
jie=data(:,14:16);
jiu=data(:,17:19);

jei=jei./5;
jeu=jeu./1.3;

X={jue,jeu,jei,jui,jie,jiu};
name={'UE','EU','EN','UN','NE','NU'};

figure,
for j=1:6
    subplot(3,2,j),
    set(0,'DefaultAxesColorOrder',[0 0 1;0 .6 0;1 0 0;0 0 0],...
        'DefaultAxesLineStyleOrder','-|-.|--|:')
    bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
    h1=gca;
    set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
    set(h1,'Fontsize',8)
    h2=axes('Position',get(h1,'Position'));
    set(h2,'Fontsize',8)
    plot(X{j}(:,2),'k','LineWidth',2);
    hold on, plot(X{j}(:,1),'k','LineWidth',1,'LineStyle','--');
    hold on, plot(X{j}(:,3),'k','LineWidth',1,'LineStyle','--');
     set(h2,'YAxisLocation','left','Color','none')
    ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
    % ylim(h2,[4.9 6.3])
    text(-70,3,name{j}), ylim([-3 3])
    set(gca','Xticklabel',num2str((1980:10:2015)'))
    set(gca,'Xtick',1+4*12:12*10:length(nber)), xlim([1 length(nber)]),
    set(h2,'XLim',get(h1,'XLim'),'Layer','top')
end



